package com.jiuyue.excel_time.controller;

import com.alibaba.excel.EasyExcel;
import com.jiuyue.excel_time.component.CustomerExcelDataListener;
import com.jiuyue.excel_time.entity.CustomerExcel;
import com.jiuyue.excel_time.service.CustomerExcelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @description: TODO
 * @author: Shihaiqing
 * @date: 2023-12-26 10:09
 * @version: 1.0
 **/
@RestController
@RequestMapping("/excel")
@Slf4j
public class TestController {


    @Resource
    private CustomerExcelService customerExcelService;

    @PostMapping("/import/user")
    public void importUserExcel() {
        try {
            String fileName = "F:\\customer_01.xlsx";
            log.info("模板地址========"+fileName);
            // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
            EasyExcel.read(fileName, CustomerExcel.class, new CustomerExcelDataListener(customerExcelService)).sheet().doRead();
        } catch (Exception e) {
           e.printStackTrace();
        }
    }





}
